- /* slftancf.cpp by K.Tsuru */
- // function ID 4104 DRADIX
- /*********************************************
- SLong class
- It makes a table of tangent coefficients T[n]
- using the combination number combL().
- T[0] = 0, T[n] = Tn (n>0)
- **********************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static SNBlock<SLong>* T = NULL; //It keeps the result of calculation.
- static uint upto = 0; //How many terms have been calculated ? Tn(upto) ok
-
- void TanCoeffFree(){
- if(upto == 0) return;
- T->size(0,-1); T = NULL; upto = 0;
- }
-
- SLong TanCoeff(uint m){
- if(!upto){ //first call
- T = new SNBlock<SLong>(minArraySize);
- (*T)[0].SetSmall(1); upto = 1;
- }
- if(!m){ //free memory
- TanCoeffFree();
- return 0.0;
- } else if(m <= upto) return (*T)[m-1]; // T(m) = T[m-1] m-1 <= upto
-
- uint j, n;
- SLong sum, f;
- if(T->reserve(m) == 0) f.SetError(f.OUT_OF_RANGE,"TanCoeff", 4104);
- //cout << "m= " << m << " T->size() = " << T->size()<< endl;
- for(n = 1; n < m ; n++){
- sum.SetSmall((n & 1) ? -1 : 1);
- for(j = 1; j <= n ; j++){
- f = combL(2*n+1, 2*j)*(*T)[n-j];
- if(j & 1) sum += f;
- else sum -= f;
- }
- (*T)[n] = sum;
- }
- upto = m;
- return (*T)[m-1];
- }
slftancf.cpp : last modifiled at 2017/06/23 10:37:54(1,238 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).